﻿using System;
using System.Configuration;
using System.Reflection;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 日志模板元素
    /// </summary>
    public sealed class TemplateElement : ConfigurationElement
    {
        /// <summary>
        /// type属性
        /// </summary>
        [ConfigurationProperty("type", IsRequired = false, DefaultValue = "Alex.Library.Log.DefaultTemplate,Alex.Library.Log")]
        public string Type
        {
            get
            {
                return (string)this["type"];
            }
        }

        /// <summary>
        /// 获取日志模板对象
        /// </summary>
        /// <returns></returns>
        public ILogInfoTemplate GetTemplate()
        {
            try
            {
                System.Type type = System.Type.GetType(this.Type);
                ILogInfoTemplate temp = (ILogInfoTemplate)System.Activator.CreateInstance(type);
                return temp;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
    }
}
